package com.servlet;

import com.dao.imp.AddUpdDelDaoImp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

/**
 * @author Mathison
 * @Title: ${NAME}
 * @Package: ${PACKAGE_NAME}
 * @Description: TODO
 * @date 2021/11/25 20:52
 **/

@WebServlet(name = "AddAddressServlet", value = "/AddAddressServlet")
public class AddAddressServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        int user_id = Integer.parseInt(session.getAttribute("userId").toString());

        String receiver = request.getParameter("receiver");
//        System.out.println(receiver);
        String province = request.getParameter("province");
        String city = request.getParameter("city");
        String full_address = request.getParameter("full_address");
        String receiver_phoneNum = request.getParameter("receiver_phoneNum");
        int postCode = Integer.parseInt(request.getParameter("postCode"));

        String sql = "INSERT INTO address (receiver, province, city, full_address, receiver_phoneNum, postCode, user_id) VALUES (\"" +
                receiver+"\",\"" +
                province+"\" ,\"" +
                city+"\" ,\"" +
                full_address+"\" ," +
                receiver_phoneNum+" ," +
                postCode+"," +
                user_id+
                ")";

//System.out.println(sql);

        AddUpdDelDaoImp addUpdDelDaoImp = new AddUpdDelDaoImp();
        addUpdDelDaoImp.addUpdDelGoods(sql);
    }

}
